//操作成功之后提示
function success(text){
	  $("#alerts").html("<div  style='text-align: center; display:no;' class='alert alert-success alert-dismissable'><strong>"+text+"</strong></div>");
	  $("#menus").click();
}
//操作失败之后提示
function fail(text){
	  $("#alerts").html("<div  style='text-align: center; display:no;' class='alert alert-success alert-dismissable'><strong>"+text+"</strong></div>");
	  $("#menus").click();
}
function myfresh(){
	window.location.href=window.location.href;
}
//一下是商品上传的js
$("button[name='addNewSeriesButton']").click(function(){
	var lLable=makeUlOfHead("addNewSeries","上架新系列产品");
	if($("#ulHead").find("a[href='#addNewSeries']").length==0){
		$("#ulHead").append(lLable);
		var modelId=$(this).parent().attr("id");
		var index=$("#ulHead").find("a[href='#"+modelId+"']").parent().index()+1;
		$('#ulHead li:eq('+index+') a').tab('show');
	}
});

//点击老系列上传
$("button[name='addOldSeriesButton']").click(function(){
	var lLable=makeUlOfHead("addOldSeries","上架已有系列产品");
	if($("#ulHead").find("a[href='#addOldSeries']").length==0){
		$("#ulHead").append(lLable);
		var modelId=$(this).parent().attr("id");
		var index=$("#ulHead").find("a[href='#"+modelId+"']").parent().index()+1;
		$('#ulHead li:eq('+index+') a').tab('show');
	}	
	
});
//点击布艺帘
$("button[name='addBuYiLianButton']").click(function(){
	var lLable=makeUlOfHead("addGoodsDeatil","布艺帘(商品信息)上架");
	if($("#ulHead").find("a[href='#addGoodsDeatil']").length==0){
		$("#ulHead").append(lLable);
		var modelId=$(this).parent().attr("id");
		var index=$("#ulHead").find("a[href='#"+modelId+"']").parent().index()+1;
		$('#ulHead li:eq('+index+') a').tab('show');
	}		
});
//点击成品帘
$("button[name='addFinishShadeButton']").click(function(){
	var lLable=makeUlOfHead("addGoodsDeatil2","成品帘(商品信息)上架");
	if($("#ulHead").find("a[href='#addGoodsDeatil2']").length==0){
		$("#ulHead").append(lLable);
		var modelId=$(this).parent().attr("id");
		var index=$("#ulHead").find("a[href='#"+modelId+"']").parent().index()+1;
		$('#ulHead li:eq('+index+') a').tab('show');
	}		
});
//点击配件
$("button[name='addAccessButton']").click(function(){
	var lLable=makeUlOfHead("addGoodsDeatil3","配件(商品信息)上架");
	if($("#ulHead").find("a[href='#addGoodsDeatil3']").length==0){
		$("#ulHead").append(lLable);
		var modelId=$(this).parent().attr("id");
		var index=$("#ulHead").find("a[href='#"+modelId+"']").parent().index()+1;
		$('#ulHead li:eq('+index+') a').tab('show');
	}		
});

//将序列化字符串转成json字符串
function updateString(data){
    data=data.replace(/&/g,"\",\"");  
    data=data.replace(/=/g,"\":\"");  
    data="{\""+data+"\"}";  	
    return data;
}
function youliantou(){
	
	$("#kuanshi").append("<label>　帘头款式:　</label>" +
			'<input type="text" name="shadeDesign"  />');
	$("#kuanshi").append("<label>　帘头单价:　</label>" +
			'<input type="text" name="llprice"  />');
}
function wuliantou(){
	$("#kuanshi").empty();
}
function addSha(){
	$(".form-group1").remove();
	var shaEle = '<div class="form-group1 row" style="margin: 0 -15px 15px -15px;position: relative;margin-top: 9px;"><label class="col-sm-2 control-label">打孔价格</label><div class="col-lg-2"><input type="text" name="holePrice" class="form-control" placeholder="" style="position: relative;margin-top: 1px;width:100px"><div style="position: relative;margin-top: -28px;margin-left: 109px;"></div></div></div><div class="form-group1 row" style="margin: 0 -15px 15px -15px;position: relative;margin-top: 9px;"><label class="col-sm-2 control-label">韩折价格</label><div class="col-lg-2"><input type="text" name="ssPrice" class="form-control" placeholder="" style="position: relative;margin-top: 1px;margin-left:1px;width:100px"/><div style="position: relative;margin-top: -28px;margin-left: 109px;"></div></div></div>'
	$("#defaultForm_1").append(shaEle);
		
}
function addBu(){
	var buEle = '<div class="form-group1 row" style="margin: 0 -15px 15px -15px;position: relative;margin-top: 9px;"><label class="col-sm-2 control-label">打孔价格</label><div class="col-lg-2"><input type="text" name="holePrice" class="form-control" placeholder="" style="position: relative;margin-top: 1px;width:100px"><div style="position: relative;margin-top: -28px;margin-left: 109px;"></div></div></div><div class="form-group1 row" style="margin: 0 -15px 15px -15px;position: relative;margin-top: 9px;"><label class="col-sm-2 control-label">韩折价格</label><div class="col-lg-2"><input type="text" name="zhePrice" class="form-control" placeholder="" style="position: relative;margin-top: 1px;margin-left:1px;width:100px"/><div style="position: relative;margin-top: -28px;margin-left: 109px;"></div></div></div>'
	
	$("#defaultForm_1").append(buEle);
	
}

function tianjiaStyleLocation(){
	$.post(
			"/bukeManage/shoppingmall/tianjiaStyleLocation.do",
			{
			},
			function(data){
				var labelDiv = $("#fengge");
				var changjing = $("#changjing");
				var styles = data.styles;
				var locations = data.locations;
				for(var a=0;a<styles.length;a++){
					labelDiv.append(makeLable(styles[a].styleId,styles[a].styleContent));
				}
				for(var a=0;a<locations.length;a++){
					changjing.append(makeLable(locations[a].locationId,locations[a].locationContent));
				}
			},
			"json"
	);
}
function tianjiaStyle(){
	$.post(
			"/bukeManage/shoppingmall/tianjiaStyleLocation.do",
			{
			},
			function(data){
				var labelDiv = $("#fengge");
				var styles = data.styles;
				for(var a=0;a<styles.length;a++){
					labelDiv.append(makeLable(styles[a].styleId,styles[a].styleContent));
				}
			},
			"json"
	);
}
function tianjiaLocation(){
	$.post(
			"/bukeManage/shoppingmall/tianjiaStyleLocation.do",
			{
			},
			function(data){
				var changjing = $("#changjing");
				var locations = data.locations;
				for(var a=0;a<locations.length;a++){
					changjing.append(makeLable(locations[a].locationId,locations[a].locationContent));
				}
			},
			"json"
	);
}
/*成品帘类别*/
function addChengPL(){
	$.post("/bukeManage/shoppingmall/chengpinlianstyle.do",function(data){
		var data = JSON.parse(data);
		var finType = data.finType;
		//console.log(finType);
		for(var i=0;i<finType.length;i++){
			var labelEle = '<label style="margin:0 5px"><input type="radio" name="fptId" value="'+finType[i].fptId+'">'+finType[i].fptBody+'</label>';
			$("#kinds").append(labelEle);
		}
		
		
	})
}
/*配件类别*/
function addPJ(){
	$.post("/bukeManage/shoppingmall/peijianstyle.do ",function(data){
		var data = JSON.parse(data);
		var acc = data.acc;
		for(var i=0;i<acc.length;i++){
			var labelEle = '<label style="margin:0 5px"><input type="radio" name="accessoriesTypeId" value="'+acc[i].accessoriesTypeId+'">'+acc[i].accessoriesTypeContent+'</label>';
			$(".session").append(labelEle);
		}
		
	})
}
/*添加布艺帘多个商品详情图*/
var imgData = [];
$(".addImg").click(function(){
	if($('.addVal').val() == ""){
		alert("请输入图片名称");
	}else{
		var spanEle ='<span>'+$('.addVal').val()+'<br>'+'</span>';
		$(".imgBox").append(spanEle);
		$(".imgBox span").click(function(){
			//console.log("2222222");
			$(this).remove();
		})
		//console.log($(".imgBox"))
		imgData.push(spanEle);
		//console.log(data);
		$('.addVal').val("");
	}
})
/*添加成品帘多个商品详情图*/
var imgData1 = [];
$(".addImg1").click(function(){

	if($('.addVal1').val() == ""){
		alert("请输入图片名称");
	}else{
		var spanEle ='<span>'+$('.addVal1').val()+'<br>'+'</span>';
		$(".imgBox1").append(spanEle);
		$(".imgBox1 span").click(function(){
			
			$(this).remove();
		})
		
		imgData1.push(spanEle);
		
		$('.addVal1').val("");
	}
})
/*添加配件多个商品详情图*/
var imgData2 = [];
$(".addImg2").click(function(){
	
	if($('.addVal2').val() == ""){
		alert("请输入图片名称");
	}else{
		var spanEle ='<span>'+$('.addVal2').val()+'<br>'+'</span>';
		$(".imgBox2").append(spanEle);
		$(".imgBox2 span").click(function(){
		
			$(this).remove();
		})
		imgData2.push(spanEle);
		$('.addVal2').val("");
	}
})

//上传布艺帘商品
var styleIds = "";
var locationIds = "";
var str2 = "";
$("#buYiLianNext").click(function(){
	var r = $("#fengge input:checked");
	for(var a=0;a<r.length;a++){
		if(a==0){
			styleIds+="[";
		}
		if(a<r.length-1){
			styleIds+=r[a].value+",";
		}
		if(a==r.length-1){
			styleIds+=r[a].value+"]";
		}

	}
	var l = $("#changjing input:checked");
	for(var a=0;a<l.length;a++){
		if(a==0){
			locationIds+="[";
		}
		if(a<l.length-1){
			locationIds+=l[a].value+",";
		}
		if(a==l.length-1){
			locationIds+=l[a].value+"]";
		}
		
	}
	//获取组成 JSON.stringify
	var form = $("#addGoodsDeatil form");
	var compositions = new Array();
	for(var i=1;i<form.length;i++){
		var aa = form.eq(i);
		var str = aa.serialize();
		str = decodeURIComponent(str,true);
		str = updateString(str);
		compositions[i-1]=JSON.parse(str);
	}
	var sampleImg = $("#sampleImg>img").attr("src");
	
	var makeImg = $("#makeImg>img").attr("src");

	var str1 = $("#sampleT").serialize();	
	//获取详情图片 
	var detailsImg = new Array();
	var imgs = $("div[name='tupianDiv'] img");
	var j=0;
	for(var i=0;i<imgs.length;i++){
		if(imgs[i].name!="cuoPng"){
			detailsImg[j] = $(imgs[i]).attr("src");
			j++;
		}
	}
	
	str1=decodeURIComponent(str1,true);
	str2 ="styleIds="+styleIds+"&locationIds="+locationIds;
	str2 = updateString(str2);
	str1 = updateString(str1);
	
	/*表单提交*/
	var validator = $("#sampleT").validate({
        rules : {
            // 对应表单元素的name属性
            "serialnumber" : {required:true},
            "brand" : {required:true},
            "sampleDescribe" : {required:true},
            "swag" : {required:true},
            "isSty" : {required:true},
            "style" : {required:true},
            "holePeice" : {required:true,number:true},
            "zhePrice" : {required:true,number:true},
            "fengmian" : {required:true},
            "hem" : {required:true},
            "shading" : {required:true},
            "washing" : {required:true},
            "times_fold" : {required:true},
            "minWide" : {required:true,number:true},
            "maxWide" : {required:true,number:true},
            "minHigh" : {required:true,number:true},
            "maxHigh" : {required:true,number:true},
        },
        messages : {
        	"hem":{required:'请输入折边'},
        	"shading":{required:'请输入遮光率'},
        	"isSty":{required:'请选择图片款式'},
        	"times_fold" : {required:'请输入倍折'},
        	"fengmian":{required:'请输入计价单位'},
            "serialnumber" : {required:'请输入型号'},
            "brand" : {required:'请输入品牌'},
            "swag" : {required:'请选择图片款式'},
            "holePeice" : {required:'请输入打孔价格'},
            "zhePrice" : {required:'请输入韩褶价格'},
            "washing" : {required:'请输入洗涤说明'},
            "sampleDescribe" : {required:'请输入描述'},
            "style" : {required:'请选择风格'},
            "minWide" : {required:'请输入最小宽度  '},
            "maxWide" : {required:'  请输入最大宽度'},
            "minHigh" : {required:'请输入最小高度  '},
            "maxHigh" : {required:'  请输入最大高度'},
        	
        },
        errorElement : "span",
        errorPlacement: function(error, element) {
            error.appendTo(element.parent());
        }
     })
     if(validator.form()){
    	 var img = '<img src="/bukeManage/images/wait.gif" class="waitImg"/>';
    	 $("#addGoodsDeatil").append(img);
    	 
	     if($("#sampleT").serialize()){
	    	 $.post(
	 				"/bukeManage/shoppingmall/addgoods.do",
	 				{
	 					supplier:"",
	 					sample:str1,
	 					properties:str2,
	 					compositions:JSON.stringify(compositions),
	 					"assist":JSON.stringify(imgData)
	 				},
	 				function(data){
	 					if(validator.form()){
	 						if(data == "1"){
	 							alert("上传成功");
	 							$("#addGoodsDeatilbody img").remove();
	 							$("#addGoodsDeatil form")[0].reset();
	 							str2 = "";
	 							$(".imgBox").html("");
	 							location.reload();
	 							window.location.href='/bukeManage/shoppingmall/toOldGoods.do?currentPage=1&state=0';
	 						}else if(data=="2"){
	 							alert("请确认图片地址能够正常访问");
	 						}else{
	 							alert("上传失败");
	 							$("#addGoodsDeatilbody img").remove();
	 						}
	 					}
	 				},
	 				"json"
	 		 );
	    	 
	     } 
     }
});
//上传成品帘商品
$("#byBtn").click(function(){
	//获取组成 JSON.stringify
	var form = $("#addGoodsDeatil2 form");
	
	var compositions = new Array();
	for(var i=1;i<form.length;i++){
		var aa = form.eq(i);
		var str = aa.serialize();
		str = decodeURIComponent(str,true);
		str = updateString(str);
		compositions[i-1]=JSON.parse(str);
		
	}
		
	var sampleImg = $("#sampleImg>img").attr("src");
	
	var makeImg = $("#makeImg>img").attr("src");
	
	var str1 = form.serialize();
	console.log(str1);
	
	//获取详情图片 
	var detailsImg = new Array();
	var imgs = $("div[name='tupianDiv'] img");
	var j=0;
	for(var i=0;i<imgs.length;i++){
		if(imgs[i].name!="cuoPng"){
			detailsImg[j] = $(imgs[i]).attr("src");
			j++;
		}
	}
	var imgs = {};
	imgs.mainImg = sampleImg;
	
	imgs.makeImg = makeImg;
	imgs.assistImg = detailsImg;
	console.log(imgs);
	str1=decodeURIComponent(str1,true);
	
	
	str1 = updateString(str1);
	console.log(JSON.stringify(imgs));
	/*表单提交*/
	var validator = $("#sampleT1").validate({
        rules : {
            // 对应表单元素的name属性
            "serialnumber" : {required:true},
            "price" : {required:true,number:true},
            "shading" : {required:true},
            "brand" : {required:true},
            "sampleImg":{required:true},
            "material":{required:true},
            "supplier":{required:true},
            "chargeUnit":{required:true}
        },
        messages : {
            "serialnumber" : {required:'请输入型号'},
            "material" : {required:'请输入材质'},
            "supplier" : {required:'请输入厂家名称'},
            "sampleImg" : {required:'请输入图片名'},
            "chargeUnit" : {required:'请输入计价单位'},
            "shading" : {required:'请输入遮光率'},
            "price" : {required:'请输入价格'},
            "brand" : {required:'请输入品牌'},
        },
        errorElement : "span",
        errorPlacement: function(error, element) {
            error.appendTo(element.parent());
        }
     })
     
     if(validator.form()){
    	
    	 var img = '<img src="/bukeManage/images/wait.gif" class="waitImg"/>';
    	 $("#addGoodsDeatil2").append(img);
		 
    	 $.post(
 				"/bukeManage/shoppingmall/addgoods.do",
 				{
 					supplier:$('#vender').val(),
 					sample:str1,
 					compositions:JSON.stringify(compositions),
 					"assist":JSON.stringify(imgData1)
 				},
 				function(data){
 					
					if(data == "1"){
						alert("上传成功");
						$("#addGoodsDeatil2 img").remove();
						$("#addGoodsDeatil2 form")[0].reset();
						$(".imgBox1 span").remove();
						window.location.href='/bukeManage/shoppingmall/toOldGoods.do?currentPage=1&state=0';
					}else if(data=="2"){
						alert("请确定图片地址能够正常访问");
					}else{
						alert("上传失败");
						$("#addGoodsDeatil2 img").remove();
					}	
 				},
 				"json"
 		 );
     } 
});
//上传配件商品
$("#pjBtn").click(function(){
	//获取组成 JSON.stringify
	var form = $("#addGoodsDeatil3 form");
	
	var compositions = new Array();
	for(var i=1;i<form.length;i++){
		var aa = form.eq(i);
		var str = aa.serialize();
		str = decodeURIComponent(str,true);
		str = updateString(str);
		compositions[i-1]=JSON.parse(str);
		
	}
		
	var sampleImg = $("#sampleImg>img").attr("src");
	;
	var makeImg = $("#makeImg>img").attr("src");
	
	var str1 = form.serialize();
	console.log(str1);
	
	//获取详情图片 
	var detailsImg = new Array();
	var imgs = $("div[name='tupianDiv'] img");
	var j=0;
	for(var i=0;i<imgs.length;i++){
		if(imgs[i].name!="cuoPng"){
			detailsImg[j] = $(imgs[i]).attr("src");
			j++;
		}
	}
	var imgs = {};
	imgs.mainImg = sampleImg;
	
	imgs.makeImg = makeImg;
	imgs.assistImg = detailsImg;
	console.log(imgs);
	str1=decodeURIComponent(str1,true);
	str1 = updateString(str1);
	console.log(JSON.stringify(imgs));
	/*表单提交*/
	var validator = $("#sampleT2").validate({
        rules : {
            // 对应表单元素的name属性
            "serialnumber" : {required:true},
            "holePeice" : {required:true,number:true},
            "shading" : {required:true,number:true},
            "brand" : {required:true},
            "chargeUnit" : {required:true},
        },
        messages : {
            "serialnumber" : {required:'请输入型号'},
            "shading" : {required:'请输入遮光率'},
            "holePeice" : {required:'请输入价格'},
            "brand" : {required:'请输入品牌'},
            "chargeUnit" : {required:'请输入计价单位'},
        },
        errorElement : "span",
        errorPlacement: function(error, element) {
            error.appendTo(element.parent());
        }
     })
     
     if(validator.form()){
    	 var img = '<img src="/bukeManage/images/wait.gif" class="waitImg"/>';
    	
    	 $("#addGoodsDeatil3").append(img);
    	 
    	 $.post(
 				"/bukeManage/shoppingmall/addgoods.do",
 				{
 					supplier:$('#vender').val(),
 					sample:str1,
 					compositions:JSON.stringify(compositions),
 					"assist":JSON.stringify(imgData2)
 				},
 				function(data){
					if(data == "1"){
						alert("上传成功");
						$("#addGoodsDeatil3 img").remove();
						$("#addGoodsDeatil3 form")[0].reset();
						window.location.href='/bukeManage/shoppingmall/toOldGoods.do?currentPage=1&state=0';
					}else if(data == "2"){
						alert("请确定图片地址能够正常访问");
					}else{
						alert("上传失败");
					}	
 				},
 				"json"
 		 );
     }
	
	 
});
//选纱中点击选帘头

function selectLianTou(){
	var lLable=makeUlOfHead("addLianTou","帘头选择");
	if($("#ulHead").find("a[href='#addLianTou']").length==0){
		$("#ulHead").append(lLable);
		$("#addZhuBu>div").append(makeFrom);
		var modelId=$("#selectLianTou").parent().attr("id");
		console.log("我看看id=",modelId);
		var index=$("#ulHead").find("a[href='#"+modelId+"']").parent().index()+1;
		$('#ulHead li:eq('+index+') a').tab('show');
	}		
	
	
}
function drag(obj){
	$("div[name='tupianDiv']").val(obj.name);
	$("div[name='tupianDiv']").data(obj.name,$(obj).attr("src"));
	
}
function drop(obj,event){
	event.preventDefault();
	var imgName =  $("div[name='tupianDiv']").val();
	$("div[name='tupianDiv'] img[name='"+imgName+"']").attr("src",$(obj).attr("src"));
	$(obj).attr("src",$("div[name='tupianDiv']").data(imgName));
}
function over(event){
	event.preventDefault();
}

//显示多张图片
function inputPhotoChange(object) {
	
	var file =$(object)[0];
	
    if(window.FileReader){
    	for(var i=0;i<file.files.length;i++){
		       	       var fr = new FileReader();
		       	  	   var test =file.files[i];
		       	  	   fr.readAsDataURL(test);
		       	  	   fr.onload = function (e){ 
	 	       	  		   if($(object).parent().parent().find('div[name="tupianDiv"]').length==0){
	 	       	  			    var div=$('<div class="form-group" name="tupianDiv"></div>');
		 		       	  		 var zhengqu=$('<img name="upImg0" style="width: 140px;height: 178px;position: relative;margin-left: 10px;margin-top:-0px" src="'+e.target.result+'" ondragStart="drag(this)"  ondrop="drop(this,event)" ondragover="over(event)" draggable="true" >');
		 	       	  			 var cuowu=$('<img name="cuoPng" onclick="cuoImgClick(this)" src="../images/cuo.png" style="position: relative;margin-left: -33px;margin-top: -126px;">');
		 	       	  			 div.append(zhengqu);
		 	       	  			 div.append(cuowu);
		 	       	  			 $(object).parent().after(div);	
	 	       	  		   }else {
	 	       	  			 var zhengqu=$('<img name="upImg'+($("div[name='tupianDiv']>img").length/2)+'" style="width: 140px;height: 178px;position: relative;margin-left: 10px;margin-top:-0px" src="'+e.target.result+'" ondrop="drop(this,event)" ondragover="over(event)" ondragStart="drag(this)"  draggable="true" >');
	 	       	  			 var cuowu=$('<img name="cuoPng" onclick="cuoImgClick(this)" src="../images/cuo.png" style="position: relative;margin-left: -33px;margin-top: -126px;">');
	 	       	  			 $(object).parent().parent().find('div[name="tupianDiv"]').first().append(zhengqu);
	 	       	  			 $(object).parent().parent().find('div[name="tupianDiv"]').first().append(cuowu);
	 	       	  		   }
		       	  	   };  	       	  				
		       	    	   
  	  			}
    }
}

//提交存商品
function addGoOnZhuBu(){
	var a=1;
	$.each($("#rootDiv>form").find('h3'),function(b,inx){
		a++
	});
	$("#rootDiv").append(makeFrom(a));
	$('#rootDiv').append(deleteChuangHu());
	$(".delect").click(function(){
		$(this).parent("div").prev("form").remove();
		$(this).hide();
	})
}
$(".btn-NextOne").click(function(){
	addGoOnZhuBu();
})
function deleteChuangHu(){
	var div=$('<div class="row" style="position:relative;margin-left: 195px;"></div>');
	div.append('<button style="position: relative;margin-left: 471px;margin-top: -68px;" class="btn btn-danger delect" type="button">'+"删除该信息"+'</button><br>');
	return div
}

$("#addGoOnPeiBu").click(function(){
	$("#addPeiBu>div").append(makeFrom);
	
});
//配布中, 点击上传商品
$("#peiBuButtonNext").click(function(){
	//开始上传商品
});
$("#addGoOnSha").click(function(){
	$("#addSha>div").append(makeFrom);
	
});

function makeUlOfHead(idName,stringName){
	var aLable='<a href="#'+idName+'" data-toggle="tab">'+stringName+'</a>';
	var lLable=$("<li class=''></li>");
	lLable.append(aLable);
	return lLable;
}

//上传主布,配布,纱,都要用js拼, 因为他可能要多个 这里写一个生成主布的方法
//这个方法生成key 和空格
function makeDivInput(inputName,lableString){
	var lab='<label>'+lableString+'</label>';
	var input='<input type="text" name="'+inputName+'" placeholder="'+lableString+'">';
	var divForm=$('<div></div>');
	divForm.append(lab);
	divForm.append(input);
	return divForm;
}
//返回组成的
function makeFrom(number){
	var form=makeFormId(number);
	var rootDiv=$('<div id=""></div>');
	rootDiv.append('<hr>');
	rootDiv.append('<h3>组成'+number+'</h3>');
	rootDiv=shengcDiv(rootDiv);
	form.append(rootDiv);
	return form;
}

//写一个主布 配布 纱 遮光里布 半遮光里布 花边
function shengcDiv(rootDiv){
	rootDiv.append(makeTiTou("类型:"));
	var leixingbradioFather=makeRadioFather("leixing");
	leixingbradioFather.append(makeRadio("type",1,"主布",""));  
	leixingbradioFather.append(makeRadio("type",2,"配布",""));
	leixingbradioFather.append(makeRadio("type",3,"纱",""));
	rootDiv.append(leixingbradioFather);
	rootDiv.append(makeInput('商品图片','Img',''));
	rootDiv.append(makeInput('型号','serialnumber',''));
	rootDiv.append(makeInput('材质','material',''));
	rootDiv.append(makeInput('花距','spur','米'));
	rootDiv.append(makeTiTou("规格:"));
	var leixingbradioFather=makeRadioFather("guige");
	leixingbradioFather.append(makeRadio("breadthStatus",0,"定高",""));
	leixingbradioFather.append(makeRadio("breadthStatus",1,"定宽",""));
	rootDiv.append(leixingbradioFather);
	rootDiv.append(makeInput('幅宽','breadth','米'));
	rootDiv.append(makeTiTou("拼接方式:"));
	var leixingbradioFather=makeRadioFather("pinjie");
	leixingbradioFather.append(makeRadio("putTogether",0,"不拼接",""));
	leixingbradioFather.append(makeRadio("putTogether",1,"横拼",""));
	leixingbradioFather.append(makeRadio("putTogether",2,"竖拼",""));
	rootDiv.append(leixingbradioFather);
	rootDiv.append(makeInput('拼接米数','putNumber','米'));
	rootDiv.append(makeTiTou("能否倒幅:"));
	var leixingbradioFather=makeRadioFather("daofu");
	leixingbradioFather.append(makeRadio("inverte",1,"是",""));
	leixingbradioFather.append(makeRadio("inverte",0,"否",""));
	rootDiv.append(leixingbradioFather);
	rootDiv.append(makeInput('采购价','purchasePrice','元'));
	rootDiv.append(makeInput('出售价','price','元'));
	rootDiv.append(makeInput('供货商','supplier',''));
	rootDiv.append(makeInput('产地','produceArea',''));
	rootDiv.append(makeInput('打孔价格','holePrice',''));
	rootDiv.append(makeInput('韩折价格','zhePrice',''));
	rootDiv.append(makeInput('纱韩折价格','ssPrice',''));
	return rootDiv;
}
//做input
function makeInput(labContent,inputName,inputHou){
	var div=$('<div class="form-group" style="position: relative;margin-top: 9px;"></div>');
	var lab=$('<label class="col-sm-2 control-label">'+labContent+'</label>');
	var input=('<input type="text" name="'+inputName+'" class="form-control" placeholder="" style="position: relative;margin-top: 1px;width:100px"><div style="position: relative;margin-top: -28px;margin-left: 109px;">'+inputHou+'</div>');
	var div2=$('<div class="col-lg-2"></div>');
	div2.append(input);
	div.append(lab);
	div.append(div2);
	return div;
}

//点击继续上传图片按钮
$(".goOnUploadButton").click(function(){
	$("#goodsDeatilUpload>div").append(makeUploadDiv);
	$("#goodsDeatilUpload>div").append("<br>");
	
});
//做上传div
function makeUploadDiv(){
	var imgDiv='<div class="fileupload-preview fileupload-exists thumbnail" style="max-width: 200px; max-height: 150px; line-height: 20px;"></div>';
	var inputDiv='<div><input type="file" class="default"></div>';
	var uploadDiv=$('<div class="fileupload fileupload-new" data-provides="fileupload"></div>');
	uploadDiv.append(imgDiv);
	uploadDiv.append(inputDiv);
	return uploadDiv;
}
//写一个风格和适用场景使用的标签
function makeLable(id,body){
	/**/
	var labels = '<lable class="checkbox-inline"><input type="checkbox" value='+id+' name="style">'+body+'</label>';
	return labels;
}
//makeFrom 写一个动态from
function makeFormId(number){
	return $('<form id="defaultForm_'+number+'" class="form-horizontal" method="post"></form>');
	
}
//做按钮
function makeButton2(id,click,content){
	var div=$('<div style="position:relative;margin-left: 195px;margin-top: 62px;"></div>');
	div.append('<button style="position: relative;margin-left: 284px;margin-top: -57px;" class="btn btn-success" id="'+id+'" type="button" onclick="'+click+'" >'+content+'</button><br>');
	return div;
}
//删除按钮
function makeButton4(id,click,content){
	var div=$('<div style="position:relative;margin-left: 195px;"></div>');
	div.append('<button style="position: relative;margin-left: 471px;margin-top: -68px;" class="btn btn-danger" id="'+id+'" type="button" onclick="'+click+'" >'+content+'</button><br>');
	return div;
}
//做题头 //安装配件也可以在这里
function makeTiTou(content){
	var div=$('<div class="form-group"></div>');
	var lable=('<label class="col-sm-2 control-label">'+content+'</label>');
	return div.append(lable);
}
//做radio父div
function makeRadioFather(name){										//left:315
	return $('<div name="'+name+'" style="position: relative; margin-left: 207px;margin-top:-41px"></div>');
}
//做radio
function makeRadio(name,value,content,change){
	var div=$('<div class="radio-inline"></div>');
	var lableInput=$('<label><input type="radio" name="'+name+'" value="'+value+'" onchange="'+change+'">'+content+'</lable>');
	
	return div.append(lableInput);	
}
function makeRadio1(name1,value1,content1,change1){
	var div=$('<div class="radio-inline"></div>');
	var lableInput=$('<label><input type="radio" name="'+name1+'" value="'+value1+'" onchange="'+change1+'">'+content1+'</lable>');
	
	return div.append(lableInput);	
}
function makeRadio2(name2,value2,content2,change2){
	var div=$('<div class="radio-inline"></div>');
	var lableInput=$('<label><input type="radio" name="'+name2+'" value="'+value2+'" onchange="'+change2+'">'+content2+'</lable>');
	return div.append(lableInput);	
}

function makeRadio1(name,value,content,change,id){
	var div=$('<div class="radio-inline"></div>');
	var lableInput=$('<label><input type="radio" id="'+id+'" name="'+name+'" value="'+value+'" onchange="'+change+'">'+content+'</lable>');
	return div.append(lableInput);
}

//图片删除按钮 
function cuoImgClick(object){
	var indexImg=$(object).index();
	var leng=$(object).parent().parent().find("img[name='upImg']").length;
	if(leng==1){
		$(object).parent().parent().remove();
	}else {
		$(object).prev().remove();
		$(object).remove();		
	}
}

//修改布艺帘
$("#xiugaiGoods").click(function(){
var str1 = $("#sampleT").serialize();
	str1=decodeURIComponent(str1,true);
	str1 = updateString(str1);
	var styleIds = "";
	var locationIds = "";
	var str2 = "";
	
	var r = $("#fengge input:checked");
	for(var a=0;a<r.length;a++){
		if(a==0){
			styleIds+="[";
		}
		if(a<r.length-1){
			styleIds+=r[a].value+",";
		}
		if(a==r.length-1){
			styleIds+=r[a].value+"]";
		}
	}
	var l = $("#changjing input:checked");
	for(var a=0;a<l.length;a++){
		if(a==0){
			locationIds+="[";
		}
		if(a<l.length-1){
			locationIds+=l[a].value+",";
		}
		if(a==l.length-1){
			locationIds+=l[a].value+"]";
		}
		
	}
	
	str2 ="styleIds="+styleIds+"&locationIds="+locationIds;
	console.log(str2);
	str2 = updateString(str2);

	var form = $(".sampleT11 form");
	var compositions = new Array();
	for(var i=0;i<form.length;i++){
		var aa = form.eq(i);
		var str = aa.serialize();
		str = decodeURIComponent(str,true);
		str = updateString(str);
		console.log(JSON.parse(str));
		compositions[i]=JSON.parse(str);
	}
	var imgData3 = [];
	var s=$('input[name="graphicDetails"]');
	for(var i=0;i<s.length;i++){
		imgData3.push(s.eq(i).val());
	}
	
	$.post(
			"/bukeManage/shoppingmall/updategoodsubmit.do",
			{
				supplier:"",
				properties:str2,
				compositions:JSON.stringify(compositions),
				"assist":JSON.stringify(imgData3),
				sample:str1
				
			},
			function(data){
			
				if(data == "1"){
					alert("修改成功");
					location.reload();
			
				}else if(data=="2"){
					alert("请确定图片能够正常访问");
				}else{
					alert("修改失败");
				}		
			},
			"json"
	 );
});

//修改成品帘
$("#xiugaiGoods1").click(function(){
	var str1 = $("#sampleT1").serialize();
		str1=decodeURIComponent(str1,true);
		str1 = updateString(str1);
		var imgData = [];
		var s=$('input[name="graphicDetails"]');
		for(var i=0;i<s.length;i++){
			imgData.push(s.eq(i).val());
		}
		var form = $("#sampleT1 form");		
		var compositions = new Array();
		for(var i=1;i<form.length;i++){
			var aa = form.eq(i);
			var str = aa.serialize();
			str = decodeURIComponent(str,true);
			str = updateString(str);
			compositions[i-1]=JSON.parse(str);	
		}
		
		$.post(
				"/bukeManage/shoppingmall/updategoodsubmit.do",
				{
					supplier:"",
					properties:str2,
					compositions:JSON.stringify(compositions),
					"assist":JSON.stringify(imgData),
					sample:str1
					
				},
				function(data){
					
					if(data == "1"){
						alert("修改成功");
						location.reload();
				
					}else if(data=="2"){
						alert("请确定图片能够正常访问");
					}else{
						alert("修改失败");
					}		
				},
				"json"
		 );
	});
//修改配件
$("#xiugaiGoods2").click(function(){
	var str1 = $("#sampleT2").serialize();
		str1=decodeURIComponent(str1,true);
		str1 = updateString(str1);
		
		var imgData11 = [];
		var s=$('input[name="graphicDetails"]');
		for(var i=0;i<s.length;i++){
			imgData11.push(s.eq(i).val());
		}
		
		var form = $("#sampleT2");
		
		var compositions = new Array();
		for(var i=1;i<form.length;i++){
			var aa = form.eq(i);
			var str = aa.serialize();
			str = decodeURIComponent(str,true);
			str = updateString(str);
			compositions[i-1]=JSON.parse(str);
			
		}
	
		$.post(
				"/bukeManage/shoppingmall/updategoodsubmit.do",
				{
					supplier:"",
					properties:str2,
					compositions:'[]',
					"assist":JSON.stringify(imgData11),
					sample:str1
				},
				function(data){
					
				if(data == "1"){
					alert("修改成功");
					location.reload();
				}else if(data=="2"){
					alert("请确定图片能够正常访问");
				}else{
					alert("修改失败");
				}		
			},
				"json"
		 );		
	});

function deleteBuLiao(sampleId,type){
	 $.ajax({
		 url:'/bukeManage/shoppingmall/deleteCompositionByType.do?sampleId='+sampleId+'&type='+type,
		 success:function(data){
			 if(data=='"0"'){
				 alert("删除成功");
				 window.location.reload();
			 }else{
				 alert("删除失败");
				 window.location.reload();
			 } 
		 }
	 });
}

var input='<div class="ad1"> <label class="only">商品详情图片:</label> <input type="text"  style="width:200px;" name="graphicDetails"></div>';

$('#add1').click(function(){
	$(".ad1:last").append("<br><div class='ad1'><label class='only'>商品详情图片:</label> <input type='text' style='width:200px;' name='graphicDetails'></div>");
});

$('#del1').click(function(){
	$(".ad1:last").remove(); 
});

$('#add2').click(function(){
	$(".row:last").append("<br><div class='row'> <label class='only'>商品详情图片:</label> <input type='text'  style='width:200px;' name='graphicDetails'></div>"); 
});

$('#del2').click(function(){
	$(".row:last").remove();
});

$('#add3').click(function(){
	$(".addVal11:last").append("<br><div class='addVal11'> <label class='only'>商品详情图片:</label> <input type='text'  style='width:200px;' name='graphicDetails'></div> "); 
});

$('#del3').click(function(){
	$(".addVal11:last").remove(); 	
});








